<template>
	<view class="page-main">
		<view class="user-info" @click="onClickLogin">
			<view class="avatar">
				<u--image :src="vuex_user.avatar||'/static/touxiang.jpg'" width="70px" height="70px" shape="circle" />
				<view class="avatar-gender-icon">
					<u-icon name="man" color="#2979ff" size="28" v-if="vuex_user.sex===1" />
					<u-icon name="woman" color="#ff007f" size="28" v-else />
				</view>
			</view>
			<view style="font-size: 28rpx;">
				{{vuex_user.nickname||"点击登录"}}
			</view>
		</view>
		<view class="cell-group-box">
			<view class="cell-group">
				<u-cell-group>
					<u-cell icon="account" isLink title="用户信息" url="userInfo/userInfo" />
					<u-cell icon="/static/bind-user.png" isLink title="绑定对象" url="bindPartner/bindPartner"
						:value="vuex_user.status===1?'已绑定':''" />
					<u-cell icon="reload" isLink title="重置亲密值" @click="onReloadIntegral()" />
					<!-- <u-cell icon="phone" isLink title="手机号" :value="user.phone" @click="showPhonePopup=true"></u-cell> -->
				</u-cell-group>
			</view>
			<view class="cell-group">
				<u-cell-group>
					<u-cell icon="setting" isLink title="界面配置" url="interfaceConfig/interfaceConfig" />
					<u-cell icon="trash" isLink title="缓存清理" @click="clearLocalCache()" />
				</u-cell-group>
			</view>
			<view class="cell-group">
				<u-cell-group>
					<u-cell icon="edit-pen" isLink title="反馈意见" url="feedback/feedback" />
					<u-cell icon="question-circle" isLink title="关于我们" url="about/about" />
				</u-cell-group>
			</view>
		</view>
		
		<login-popup v-model="showLoginPopup" />

		<!-- <u-popup closeable round="10" :show="showPhonePopup" @close="showPhonePopup=false" @open="showPhonePopup=true">
			<view class="popup-phone-title">
				<view class="explain-title">
					<u--text type="success" text="申请获取以下权限" />
				</view>
				<view class="explain-body">
					<u--text type="info" text="获得您在微信客户端绑定的手机号信息，仅用于用户伴侣之间的查找、绑定操作。" />
				</view>
			</view>
			<u-button type="success" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">同意获取</u-button>
		</u-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showLoginPopup: false,
				showPhonePopup: false,
			}
		},
		onLoad() {

		},
		onShow() {
			if (this.vuex_user.id) {
				this.$refs = false
			}
		},
		methods: {
			onClickLogin() {
				if (!this.vuex_user.id) {
					this.showLoginPopup = true
				}
			},
			onReloadIntegral() {
				uni.showModal({
					title: "提示",
					content: "确定要亲密值重置吗？",
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '重置中',
								mask: true
							});
							this.$http.post("/user/updateById", {
								id: this.vuex_user.id,
								integral: 0
							}).then((res) => {
								uni.hideLoading();
								this.vuex_user.integral= 0
								uni.$u.toast('已重置亲密值')
							}).catch(err => {
								uni.hideLoading();
								uni.$u.toast(err.message)
							})
						}
					}
				});

			},
			clearLocalCache() {
				const localCache = uni.getStorageInfoSync().currentSize;
				uni.showModal({
					title: "提示",
					content: "当前缓存" + localCache + "KB，是否清理缓存？",
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '清理中',
								mask: true
							});

							uni.removeStorageSync('lifeData');
							uni.hideLoading();
							uni.$u.toast('清理成功')
						}
					}
				});

			}
			/* onGetPhoneNumber(e) {
				console.log(e);
				if (e.detail.code) {
					//绑定手机号
					uni.request({
						url: 'https://api.weixin.qq.com/cgi-bin/token',
						method: 'GET',
						data: {
							appid: global.appid,
							secret: global.appSecret,
							grant_type: "client_credential"
						},
						success: (res) => {
							if (res.access_token) {
								uni.request({
									url: 'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=' +
										res.access_token,
									method: 'POST',
									data: {
										code: e.detail.code
									},
									success: (res) => {
										let phone = res.phone_info.purePhoneNumber
										if (phone) {
											const db = uniCloud.database();
											db.collection('user').where({
												_id: this.form._id
											}).update({
												phone: phone
											}).then((res) => {
												this.form.phone = phone
												uni.$u.toast('绑定成功');
											}).catch(errors => {
												uni.$u.toast('绑定失败')
											});
										}

									}
								});
							}
						}
					});
				}
			}, */

		}
	}
</script>

<style lang="scss">
	.page-main {
		padding: 0;
	}

	.user-info {
		padding: 30rpx 0px;
		text-align: center;
		background-image: linear-gradient(#fde5f2, transparent);

		.avatar {
			width: 70px;
			margin: auto;
			margin-bottom: 20rpx;
			position: relative;

			.avatar-gender-icon {
				position: absolute;
				top: -5px;
				right: -20px;
			}
		}
	}

	.cell-group-box {
		padding: 0 30rpx;

		.cell-group {
			background-color: rgba(255, 255, 255, 0.8);
			border-radius: 10px;
			margin-top: 30rpx;
		}
	}

	.popup-phone-title {
		padding: 70rpx 50rpx;
	}

	.explain-title {
		margin-bottom: 30rpx;
	}
</style>